<?php
/**
 * 系统回复
 */
namespace App;
use Pub\tool\Setting as SettingCache;
defined('IN_IA') or exit('Access Denied');
class Reply extends Action
{
    private $_keyword = "";  //关键字

    /**
     * Reply constructor.
     * @param string $_keyword 关键字
     */
    public function __construct($_keyword)
    {
        parent::__construct();
        $this->_keyword = $_keyword;
    }

    /**
     *响应
     */
    public function respond()
    {
        global $_W;
        $PluginApi = new PluginApi("auto");
        $_result = $PluginApi->request("setting/tryRun");
        $_result = json_decode($_result,true);
        if($_result["status"] == "success"){
            $_result = $PluginApi->request("auto/auto",array(
                "uid"=>$_W["member"]['uid']
            ));
            $_result = json_decode($_result,true);
            $_url = murl('entry//index',array('m'=>'kuyuan_fm'),true,true);
            return "您的当前".SettingCache::get(SettingCache::CURRENCY_NAME)."余额：".$_result["data"].",<a href='".$_url."'>点击前往".SettingCache::get(SettingCache::WEB_NAME)."</a>";
        }else{
            // 手动签到
            return $this->signIn();
        }
    }

    /**
     * 每日签到
     */
    private function signIn()
    {
        $SignAction = new SignIn();
        $_sign_result = $SignAction->signIn();
        $_url = murl('entry//index',array('m'=>'kuyuan_fm'),true,true);
        if($_sign_result == -1){
            return "您今日已签到"."。<a href='".$_url."'>点击前往".SettingCache::get(SettingCache::WEB_NAME)."</a>";
        }else if($_sign_result == -2){
            return "签到失败";
        }else{
            return "恭喜您，签到成功，获得".$_sign_result."个".SettingCache::get(SettingCache::CURRENCY_NAME)."。<a href='".$_url."'>点击前往".SettingCache::get(SettingCache::WEB_NAME)."</a>";
        }
    }
}
